#!/usr/bin/make -f

BUILDDIR = build_dir
COMMON_OPTIONS = -DCMAKE_INSTALL_PREFIX=../debian/tmp/usr \
                 -DSIMULATOR_INSTALL_PREFIX=/usr \
                 -DFIRMWARE_TARGET=NO \
                 -DGVARS=YES \
                 -DHELI=YES \
                 -DALLOW_NIGHTLY_BUILDS=NO \
                 -DVERSION_SUFFIX=__VERSION_SUFFIX__

STM32_OPTIONS = -DLUA=YES

# secondly called by launchpad
build:
	mkdir $(BUILDDIR);

	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) -DPCB=SKY9X    ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) -DPCB=9XRPRO   ../ ; make libsimulator

	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=X7    ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=X9D   ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=X9D+  ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=X9E   ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=X12S ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=JUMPERT12  ../ ; make libsimulator
	cd $(BUILDDIR); cmake $(COMMON_OPTIONS) $(STM32_OPTIONS) -DPCB=JUMPERT16  ../ ; make libsimulator

	make -C $(BUILDDIR) companion22 simulator22

# thirdly called by launchpad
binary: binary-indep binary-arch

binary-indep:
	# nothing to be done

binary-arch:
	# final cmake neede in order to find all simulators
	cd $(BUILDDIR); cmake ../
	cd $(BUILDDIR); cmake -P cmake_install.cmake
	mkdir debian/tmp/DEBIAN
	dpkg-shlibdeps debian/tmp/usr/bin/companion22 debian/tmp/usr/bin/simulator22 debian/tmp/usr/lib/companion22/*
	dpkg-gencontrol -popentx-companion22
	dpkg --build debian/tmp ..

# firstly called by launchpad
clean:
	rm -rf $(BUILDDIR)

.PHONY: binary binary-arch binary-indep clean
